#pragma once

#include <queue>
#include "data_structure.h"
#include "json/json.h"
#include "parse_proto.h"

#define K_ADR_LatAccelMinValue          (1.5)
// #define K_ADR_LatAccelMaxValue          (6)
#define K_ADR_LongAccelMaxValue         (-3)
// #define K_ADR_LongAccelMinValue         (-6)
#define K_ADR_LogicFaultTrq             (1)
#define K_ADR_LogicFaultAcceleration    (-1)
#define K_ADR_TakerOverSASspd           (180)
#define K_ADR_TakerOverTorq             (3)
//#define K_ADR_MissBrkJudgeMaxAcc        (-4)
#define K_ADR_DriverStrRecordSASspd     (250)
#define K_ADR_DriverStrJudgeMaxSpd      (60)
#define K_ADR_OtherDangerJudgeMaxAcc    (-3)
#define K_ADR_CutingInProb              (80)
#define K_ADR_CutingOutProb             (80)
#define K_ADR_CutingTakerOverJudgeTime  (2*1000*1000)
#define K_ADR_CutingTakerOverSASspd     (180)



typedef unsigned char (*funcp)(const string eventId, const ProtoData &data, TriggerEventInfo &retTigger);

//注意，这些信号类型定义一定要和proto里一致，否则可能造成 get_signal_from_map()传入类型不一致，获取不到值（0）
typedef struct
{
	double esp_long_accel;
	double esp_lat_accel;
	uint32_t esp_lat_accel_valid;
	uint32_t esp_long_accel_valid;    
	double esp_veh_spd;
	unsigned int event_happen_flag;
}event_BA009_para_stru;
 
typedef struct
{
	float acc_targetacceleration;
	bool acc_cddaxena;
	uint32_t vcu_ovrd_mod_req;
	float acc_acctrqreq;
	bool acc_acctrqreqena;
	uint32_t ib_brk_pedl_sts_gb;
	unsigned int event_happen_flag;
    double first_cond_trigger_time;
    double second_cond_trigger_time;
}event_BA530_para_stru;


typedef struct
{
	uint32_t elk_state;
	uint32_t sys_lngstate;
    uint32_t pd_status;
    uint32_t esp_long_accel_valid;
    double esp_long_accel;
    bool fcw_active;
    bool awb_active;
    uint32_t sys_latstate;
    unsigned int event_happen_flag;
    double timestamp;
} event_BA531_para_stru;

typedef struct
{
	uint32_t ad_lattakeoverreq;
    uint32_t old_ad_lattakeoverreq;
	uint32_t eps_steer_ag_rate;
	uint32_t eps_measured_torsion_bar_torq_valid;
	uint32_t ad_lngtakeoverreq;
    uint32_t old_ad_lngtakeoverreq;
	uint32_t ib_brk_pedl_sts_gb;
    uint32_t old_ib_brk_pedl_sts_gb;
    unsigned int event_happen_flag;
    double eps_measured_torsion_bar_torque;
    double alarm_lng_time;
    double alarm_lat_time;    
}event_BA532_para_stru;

typedef struct
{
    uint32_t m_pd_status;
    uint32_t sys_latstate;
    unsigned int event_happen_flag;
    double var2;
}event_BA007_para_stru;

typedef struct
{
    uint32_t takeover_alarm_lat_level;
    uint32_t old_takeover_alarm_lat_level;
    uint32_t takeover_alarm_lng_level;
    uint32_t old_takeover_alarm_lng_level;
}event_IT574_para_stru;

typedef struct
{
    uint32_t m_pd_status;
    uint32_t m_eps_faild;
    uint32_t m_esp_tcs_failr;
    uint32_t m_vcu_pt_tq_req_avl{1};
    double first_cond_trigger_time;
    double second_cond_trigger_time;
    double third_cond_trigger_time;
    unsigned int event_happen_flag;


    uint32_t takeover_alarm_lat_level;
    uint32_t old_takeover_alarm_lat_level;
    uint32_t takeover_alarm_lng_level;
    uint32_t old_takeover_alarm_lng_level;
}event_IT577_para_stru;

typedef struct
{
    uint32_t apa_status;
    uint32_t hmi_apadrvrreqonoff;
    uint32_t park_sst_req;
    uint32_t park_sst_notice;      
}event_BA501_para_stru;

typedef struct
{
    uint32_t sys_lngstate;
    double esp_veh_spd;
    float lateral_distance;
    float longitudinal_absolute_velocity;
    float longitudinal_distance;
    float width;
    uint32_t pd_status;
    uint32_t sys_latstate;
    uint32_t hu_nav_guigance_status;
    double esp_long_accel;
    double hu_road_curvature;
    double first_cond_trigger_time;
    double second_cond_trigger_time;
    double third_cond_trigger_time;
    unsigned int event_happen_flag;
}event_BA799_para_stru;

namespace DcAdr
{
    class SpecialTrigger
    {
    public:
        static SpecialTrigger &getInstance();
        void push2TopicMap(const std::string &topic, const std::string &eventid);
        bool isContainTopic(const std::string &topic);
        void inner_event_judge(const ProtoData &data, const std::shared_ptr<ProtoCondInfo_t> protoInfo);


        static unsigned char inner_event_judge_BA009(const string eventId, const ProtoData &data, TriggerEventInfo &retTigger);
        static unsigned char inner_event_judge_BA530(const string eventId, const ProtoData &data, TriggerEventInfo &retTigger);
        static unsigned char inner_event_judge_BA531(const string eventId, const ProtoData &data, TriggerEventInfo &retTigger);
        static unsigned char inner_event_judge_BA532(const string eventId, const ProtoData &data, TriggerEventInfo &retTigger);
        static unsigned char inner_event_judge_BA007(const string eventId, const ProtoData &data, TriggerEventInfo &retTigger);
        static unsigned char inner_event_judge_IT574(const string eventId, const ProtoData &data, TriggerEventInfo &retTigger);
        static unsigned char inner_event_judge_IT577(const string eventId, const ProtoData &data, TriggerEventInfo &retTigger);
        static unsigned char inner_event_judge_BA501(const string eventId, const ProtoData &data, TriggerEventInfo &retTigger);
        static unsigned char inner_event_judge_BA799(const string eventId, const ProtoData &data, TriggerEventInfo &retTigger);

    private:
        SpecialTrigger();
        ~SpecialTrigger();
        static void addTopic2Vec(const std::vector<std::string> &srcVec, std::vector<std::string> &desVec);

        map<string, vector<string>> m_spTrg_topicEventIDList;//是 m_topicEventIDList 的子集
        
        static event_BA009_para_stru event_BA009_para;
        static event_BA530_para_stru event_BA530_para;
        static event_BA531_para_stru event_BA531_para;
        static event_BA532_para_stru event_BA532_para;
        static event_BA007_para_stru event_BA007_para;
        static event_IT574_para_stru event_IT574_para;
        static event_IT577_para_stru event_IT577_para;
        static event_BA501_para_stru event_BA501_para;       
	    static event_BA799_para_stru event_BA799_para;   

        static double K_ADR_LatAccelMaxValue;
        static double K_ADR_LongAccelMinValue;
    };
}